package ch06;

import java.util.InputMismatchException;
import java.util.Scanner;

public class AvgMain {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        try{
            System.out.println("请输入学员总成绩：");
            int total = input.nextInt();
            System.out.println("请输入科目数：");
            int numbers = input.nextInt();
            // 判断是否非负数  手动抛出自定义异常
            if (total < 0 || numbers < 0){
                throw new MyException("数据不能为负数！");
            }
            int avg = total/numbers;
            System.out.println("学员平均分数是"+avg);
        }catch (ArithmeticException ex){
            System.out.println(ex.getMessage());
            System.out.println("不能除以0");
        }catch (InputMismatchException ex){
//            ex.printStackTrace();
            System.out.println(ex.getMessage());
            System.out.println("输入格式不匹配");
        }catch (MyException ex){
            System.out.println(ex.getMessage());
            System.out.println("数据不能为负数");
        }
        catch(Exception ex){
            System.out.println(ex.getMessage());
            System.out.println("其他异常");
        }finally {
            System.out.println("统计平均分结束！");
        }
        System.out.println("程序结束！");
    }
}
